<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	  xmlns:f="http://java.sun.com/jsf/core"
	  xmlns:h="http://java.sun.com/jsf/html"
	  xmlns:ui="http://java.sun.com/jsf/facelets" 
	  xmlns:p="http://primefaces.prime.com.tr/ui" >
	  
	<f:view contentType="text/html"/>
	<h:body>
		<ui:composition template="layout.xhtml">
		<ui:define name="conteudo">
		
		<h2>Listagem de Usuários</h2>
		<h:form id="dados">
		<p:messages id="mensagens" style="color: red" showDetail="true"/>
			<fieldset>
				<legend>Pesquisar Usuário</legend>
					<br/>
						<h:outputLabel value="Nome:" for="nome" />
						<h:inputText id="nome" value="#{usuarioBean.idAssociado}" size="70" />
				<br/><br/>
				
				 <table style="width:60%; height: 30%">
		          	<tr valign="middle">
		          		<td colspan="2" align="right" style="padding-right: 19px">
		          		
						<h:commandLink action="#{usuarioBean.pesquisarUsuario}" update="tabela" title="Pesquisar Usuário">
							<img src="resources/imagens/Ppesquisar.jpg" alt="Pesquisar"/>
						</h:commandLink>
						</td>
						<td colspan="2" align="center" style="padding-left: 19px">
							<a href="#{facesContext.externalContext.request.contextPath}/principal.xhtml" title="Cancelar">
								<img src="resources/imagens/Xcancelar.jpg" alt="Cancelar"/> </a>
						</td>
						<td colspan="2" align="left" style="padding-left: 19px">
							<a href="#{facesContext.externalContext.request.contextPath}/usuarioForm.xhtml" title="Incluir Novo Usuário">
								<img src="resources/imagens/novo.jpg" alt="Incluir Novo"/></a>
						</td>
						</tr>
						</table>
			</fieldset>
		
		<br></br>
		<br></br>
		
		<br></br>
		<h:outputText value="Nenhum registro encontrado!" rendered="#{empty usuarioBean.usuarios}" />
			<h:dataTable id="tabela" value="#{usuarioBean.usuarios}" var="user" paginator="true" rows="10" rendered="#{! empty usuarioBean.usuarios}" 
				styleClass="dados" rowClasses="impar,par" >
				
				<h:column>
					<f:facet name="header">
						<h:outputText value="Nome" />
					</f:facet>
					<h:outputText value="#{user.associado.nome}" />
				</h:column>
				<h:column>
					<f:facet name="header">
						<h:outputText value="Login" />
					</f:facet>
					<h:outputText value="#{user.login}"/>
				</h:column>
				<h:column>
					<f:facet name="header">
						<h:outputText value="Ações" />
					</f:facet>
					<h:commandLink action="usuarioForm?faces-redirect=true&amp;includeViewParams=true" title="Alterar">
						<h:graphicImage library="imagens" name="icon_alterar.jpg" alt="Alterar"/>
						<f:setPropertyActionListener value="#{user}" target="#{usuarioBean.usuario}"/>
					</h:commandLink>
					<p:commandLink title="Excluir" update=":dialogExclusao" oncomplete="confirmacao.show()">
						<h:graphicImage library="imagens" name="excluir.jpg" />
						<f:setPropertyActionListener target="#{usuarioBean.usuario}" value="#{user}"/>
					</p:commandLink>	
				</h:column>
			</h:dataTable>
		</h:form>
		<p:outputPanel id="dialogExclusao">
		<p:confirmDialog widgetVar="confirmacao" appendToBody="true" header="Confirmação" message=" Confirma a exclusão? " severity="alert">
			<h:form>
		    	<center> 
		        	<p:commandButton value="Sim" action="#{usuarioBean.remover()}" process="@form" update=":dados:tabela" oncomplete="confirmacao.hide()">
		        		<f:param name="id" value="#{usuarioBean.usuario.idUsuario}" />
		        	</p:commandButton>
		        	<p:commandButton value="Não" onclick="confirmacao.hide()" type="button" />
		        </center>
	        </h:form>
	    </p:confirmDialog>
	</p:outputPanel>
		</ui:define>
		</ui:composition>
	</h:body>
</html>